﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VK.Comm;
using VK.Casemeet.Elites;
using VK.Casemeet.Employees;

namespace VK.Casemeet.Web.Admin.Elites
{
    public partial class EliteAdd : System.Web.UI.Page
    {
        public string logo = "null.jpg";

        protected void Page_Load(object sender, EventArgs e)
        {
            (this.Master as Site).SiteMapPathControl.MapPathList = new List<MapPath>(){
                new MapPath{ Text="桌面",Url="/Admin/Home.aspx"},
                new MapPath{ Text="精英",Url="Index.aspx"},
                new MapPath{ Text="新建精英",Url="#"}
            };

            if (!IsPostBack)
            {
                txtCreated.Text = DateTime.Now.ToString();
                lbEditor.Text = EmployeeService.GetSessionEmployee().Account;
            }
        }

        protected void butSave_Click(object sender, EventArgs e)
        {
            EliteEntity elite = LoadEntity();

            if (EliteBLL.InsertElite(elite) > 0)
            {
                Message.Msg(this.Page, CS.MsgAddSuccess, MessageType.Success);
                Util.ClearControl((this.Master as Site).contentBody.Controls);
                txtCreated.Text = DateTime.Now.ToString();
                txtHits.Text = "0";
            }
            else
            {
                Message.Msg(this.Page, CS.MsgAddFailure, MessageType.Failure);
            }
        }

        protected EliteEntity LoadEntity()
        {
            EliteEntity elite = new EliteEntity();
            elite.Title = txtTitle.Text;
            elite.Content = Server.HtmlEncode(Util.GetFormString("txtContent"));
            elite.IsEnable = chkIsEnable.Checked;
            elite.Created = Util.ConverDateTime(txtCreated.Text);
            elite.Updated = Util.ConverDateTime(txtCreated.Text);
            elite.Hits = int.Parse(txtHits.Text);
            elite.Editor = lbEditor.Text;
            elite.ImgUrl = newsPhoto1.ValueUrl;
            elite.ProvinceID = EmployeeService.GetSessionEmployee().ProvinceID;
            elite.CityID = EmployeeService.GetSessionEmployee().CityID;

            return elite;
        }
    }
}